package com.neuedu.mblog.controller;

import com.neuedu.mblog.controller.BaseController;
import com.neuedu.mblog.service.UserService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;

/**
 * 项目：mblog_java4
 * 创建时间：  2022-01-01   10:32
 * 作者 :jshand
 * 描述 : 用户注册
 */
@WebServlet(urlPatterns = "/regist")
public class RegisterController extends BaseController {
    private UserService userService = new UserService();

    /**
     * http://127.0.0.1:90/mblog/regist?_type=index
     * @param request
     * @param response
     */
    public void index(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/view/front/regist.jsp").forward(request,response);
    }


    /**
     * ajax请求
     * http://127.0.0.1:90/mblog/regist?_type=regist&username=abc&password=123456
     * @param request
     * @param response
     * @throws ServletException
     * @throws IOException
     * @throws SQLException
     */
    public void regist(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException, SQLException {

        //用户名、密码
        boolean succcess = userService.regist(request);

        //响应json内容
        super.jsonResult(response,succcess);
    }


}
